layui.use(['layer','form'],function () {
    var form = layui.form;
    var layer=layui.layer;

    //登陆验证
    var loginId_p=$.cookie('loginAdminId');//获取cookie
    if (loginId_p==null||loginId_p=='null'){//判断是否登陆 =null=没登陆
        layer.alert("您还未登录",function () {
            window.location.replace("/games_info_sys/backstage_web/login.html");
        });
    }else if(atob(loginId_p).indexOf("Logined:")==0) {//登陆状态中

        form.on('submit(game_form)', function (data) {

            $.ajax({
                url: "/games_info_sys/games/edit.do",
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.data == 1) {
                        layer.alert('修改成功', function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                },
                error: function () {
                    layer.msg("提交出错,请检查网络");
                }
            });
            return false;//禁止表单跳转
        });

        form.on('submit(game_Addform)', function (data) {

            $.ajax({
                url: "/games_info_sys/games/add.do",
                type: "POST",
                contentType: "application/json",
                data: JSON.stringify(data.field),
                success: function (res) {
                    if (res.data == 1) {
                        layer.alert('添加成功', function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                },
                error: function () {
                    layer.msg("提交出错,请检查网络");
                }
            });
            return false;//禁止表单跳转
        });
    }
});